<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>菜单管理</title>
<meta name="renderer" content="webkit">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<meta name="viewport"
	content="width=device-width, initial-scale=1, maximum-scale=1">
<meta name="apple-mobile-web-app-status-bar-style" content="black">
<meta name="apple-mobile-web-app-capable" content="yes">
<meta name="format-detection" content="telephone=no">

<link rel="stylesheet" type="text/css"
	href="/gm/easyui/themes/default/easyui.css">
<link rel="stylesheet" type="text/css"
	href="/gm/easyui/themes/icon.css">

<script type="text/javascript" src="/gm/jquery.min.js"></script>
<script type="text/javascript"
	src="/gm/easyui/jquery.easyui.min.js"></script>
<script type="text/javascript"
	src="/gm/server-option/server-common.js"></script>
</head>
<body>
	<table id="MenuTable" title="菜单管理" class="easyui-treegrid"
		style="width: 90%;"
		data-options="
                url: '/menu/getMenu',
                method: 'get',
                rownumbers: true,
                pagination: true,
                pageSize: 30,
                pageList: [30,60,90],
                idField: 'id',
                treeField: 'text',
                fitColumns:true,
                scrollbarSize:0,
                toolbar:toolbar
                
            ">
		<thead>
			<tr>
				<th
					data-options="field:'text',align:'left',halign:'center',width:220">菜单名称</th>
				<th
					data-options="field:'href',width:300,align:'left',halign:'center'">请求路径</th>

			</tr>
		</thead>
	</table>
	<div id="addMenuDialog" class="easyui-dialog" title="添加菜单"
		data-options="iconCls:'icon-save',resizable:true,modal:true,closed:true"
		style="width: 600px; height: 300px; padding: 20px">
		<div align="center">


			<table style="border-collapse: separate; border-spacing: 0px 10px;">
				<tr>
					<td><span id="errorTips" style="color: red"></span></td>
				</tr>
				<tr>
					<td>父类菜单： <input id="parentId" class="easyui-combobox"
						name="language" style="width: 80%;"
						data-options="
                    url:'/menu/getMenuList',
                    method:'get',
                    valueField:'id',
                    textField:'text',
                    panelHeight:'auto',
                    labelPosition: 'top'
                    ">
					</td>
				</tr>
				<tr>
					<td>菜单名称： <input class="easyui-textbox" prompt="菜单名称"
						id="name" style="width: 80%;">
					</td>
				</tr>

				<tr>
					<td>请求路径： <input class="easyui-textbox" prompt="请求路径"
						id="hrefPath" style="width: 80%;">
					</td>
				</tr>
				<tr align="center">
					<td><a href="javascript:void(0)" class="easyui-linkbutton"
						onclick="submitMenu()">--确认添加--</a></td>
				</tr>
			</table>
		</div>
	</div>

	<script>
		var toolbar = [ {
			text : '添加菜单',
			iconCls : 'icon-add',
			handler : function() {
				$("#addMenuDialog").dialog("open");
			}
		}, '-', {
			text : '删除菜单',
			iconCls : 'icon-remove',
			handler : deleteMenu
		} ];
		function deleteMenu() {
			var row = $("#MenuTable").datagrid("getSelected");
			if (row == null) {
				$.messager.alert('提示', '请选择要删除的菜单行', 'error');
				return;
			}
			$.messager.confirm('警告', '确定要删除' + row.text + '菜单吗？', function(
					r) {
				if (r) {
					
					var menuId = row.id;
					postAjax("/menu/deleteMenu/" + menuId, {},
							function(data) {
								if (data.code == 0) {
									$("#MenuTable").treegrid('reload');
									$.messager.alert('提示', '删除菜单成功');
								} else {
									$.messager.alert('提示', '服务器错误，请联系开发者:'
											+ data.msg, 'error');
								}
							});
				}
			});
		}
		function submitMenu() {
			var parentId = $("#parentId").combobox("getValue");
			if (parentId == "-1") {
				$.messager.confirm('确认', '没有选择父菜单，确认添加顶级菜单吗', function(r) {
					if (!r) {
						return;
					}
				});
			}
			var name = $("#name").val();
			var hrefPath = $("#hrefPath").val();
			var url = "/menu/addMenu";
			var json = {
				"text" : name,
				"href" : hrefPath,
				"parentId" : parentId
			};
			postAjax(url, json,
					function(data) {
						if (data.code == 0) {
							$("#addMenuDialog").dialog("close");
							$("#MenuTable").treegrid('reload');//大括号内是需要的参数
							$.messager.alert('提示', '添加菜单成功');
						} else {
							$.messager.alert('提示', '服务器错误，请联系开发者:' + data.msg,
									'error');
						}
					});

		}
	</script>
</body>
</html>